package backup;

import com.alex.cache.bean.Employee;
import com.alex.cache.dao.EmployeeDao;
import com.alex.cache.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.Cache;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * springboot-service 整合 redis
 * 手动完成缓存操作
 */
@Service
@Slf4j
public class EmployeeServiceImpl2 implements EmployeeService {

    @Resource
    private EmployeeDao employeeDao;

    @Resource
    private RedisCacheManager redisCacheManager;

    @Override
    public Employee getEmployee(Integer id) {
        log.info("查询员工: " + id);
        Employee employee = employeeDao.selectByPrimaryKey(id);
        Cache cache = redisCacheManager.getCache("emp");
        cache.put("TEST-"+Integer.valueOf(id), employee);
        return employee;
    }

    @Override
    public void delEmployee(Integer id) {

    }

    @Override
    public Employee updateEmployee(Employee employee) {
        return null;
    }

    @Override
    public Employee getEmployeeByLastname(String lastname) {
        return null;
    }

}
